<template>
	<view class="choose">
		<view class="vr">
			<view class="title">vr选房</view>
			<block v-for="(item, index) in vr" :key="index"><image :src="item.thumb" mode="widthFix"></image></block>
		</view>
		<view class="loudong">
			<view class="title"><text>选择楼房信息</text></view>
			<view class="main">
				<view class="house">
					<scroll-view class="scrollView" scroll-with-animation scroll-x>
						<view v-for="(item, index) in room" :key="index" :class="house_index == index ? 'cateItem cateActive' : 'cateItem'" @tap="select('house_index', index)">
							{{ item.build_num }}栋
						</view>
					</scroll-view>
				</view>
				<view class="room" v-if="room[house_index]">
					<block v-for="(item, index) in room[house_index]['room']" :key="index">
						<view :class="room_index == index ? 'room_name active' : 'room_name'" @tap="select('room_index', index)">{{ item.build_no }}</view>
					</block>
				</view>
			</view>
		</view>
		<view class="roomInfo">
			<view class="title">————预定详情————</view>
			<view class="info">
				<view class="row">
					<view class="text one">
						<text class="name">房间信息</text>
						<text class="content">{{ shop['name'] }}</text>
						<text class="content" v-if="room[house_index]">{{ room[house_index]['build_num'] }}</text>
						<text class="content" v-if="room[house_index]">{{ room[house_index]['room'][room_index]['floor'] }}层</text>
						<text class="content" v-if="room[house_index]">{{ room[house_index]['room'][room_index]['room_num'] }}号</text>
						<text class="content" v-if="room[house_index]">{{ room[house_index]['room'][room_index]['area'] }}平</text>
					</view>
				</view>
				<view class="row">
					<view class="text one">
						<text class="name">房产单价</text>
						<text class="content" v-if="room[house_index]">{{ room[house_index]['room'][room_index]['price'] }}万元/㎡</text>
					</view>
				</view>
				<view class="row">
					<view class="text one">
						<text class="name">房产总价</text>
						<text class="content" v-if="room[house_index]">{{ room[house_index]['room'][room_index]['total_price'] }}万</text>
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="index" @tap="goIndex()">
				<image src="../../../static/home.png" mode="widthFix"></image>
				<text>首页</text>
			</view>
			<view class="chat">
				<image src="../../../static/chat.png" mode="widthFix"></image>
				<text>在线客服</text>
			</view>
			<view class="right">
				<view class="block" @tap="addCart()"><text class="car">加入购物车</text></view>
				<view class="block" @tap="pay()"><text class="yuding">在线预定</text></view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			id: null,
			room: [],
			shop: {},
			vr: [],
			room_index: 0,
			house_index: 0
		};
	},
	onLoad(option) {
		this.id = option.id;
		this.id = 1;
		this.getData();
	},
	methods: {
		getData() {
			this.$request
				.post('landed/reserve', {
					data: {
						type: 1,
						id: this.id
					}
				})
				.then(res => {
					this.room = res.data.data.list.room;
					this.shop = res.data.data.list.shop;
					this.vr = res.data.data.list.vr;
				});
		},
		select(type, index) {
			if (type == 'room_index') {
				this.room_index = index;
			} else {
				this.room_index = 0;
				this.house_index = index;
			}
		},
		addCart() {
			let goods_id = this.room[this.house_index]['id'];
			let authData = uni.getStorageSync('authData');
			if (authData.auth) {
				this.$request
					.post('/landed/addMyCar', {
						data: {
							type: 1,
							goods_id: this.id
						},
						header: {
							Authorization: authData.auth
						}
					})
					.then(res => {
						if (res.data.code == 10000) {
							uni.showToast({
								title: '添加成功',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: '添加失败',
								icon: 'none',
								duration: 2000
							});
						}
					});
			} else {
				uni.showToast({
					title: '请先登录',
					icon: 'none',
					duration: 2000
				});
				setTimeout(function() {
					uni.navigateTo({
						url: '/pages/login/login'
					});
				}, 2000);
			}
		},
		goIndex() {
			uni.switchTab({
				url: '/pages/tabbar/tabbar-1/tabbar-1'
			});
		},
		pay() {
			let type = 1;
			let id = this.id;
			let floor_id = this.room[this.house_index]['room'][this.room_index]['id'];
			uni.navigateTo({
				url: `/pages/house_property/pay/pay?id=${id}&type=${type}&floor_id=${floor_id}`
			});
		}
	}
};
</script>

<style lang="scss">
.choose {
	width: 100%;
	background-color: #f3f3f3;
	padding-bottom: 150upx;
	.vr {
		width: 100%;
		.title {
			width: 100%;
			line-height: 100upx;
			font-size: $uni-font-size-lg;
			color: #333;
			padding: 0 20upx;
			box-sizing: border-box;
		}

		image {
			width: 100%;
		}
	}
	.selected {
		width: 100%;
		line-height: 80upx;
		font-size: $uni-font-size-base;
		color: #333;
		padding: 0 20upx;
		box-sizing: border-box;
	}
	.loudong {
		width: 100%;
		background-color: #ffffff;
		box-sizing: border-box;
		background-color: #ffffff;
		border-bottom-left-radius: 40upx;
		border-bottom-right-radius: 40upx;
		.title {
			width: 100%;
			line-height: 1.5em;
			font-size: $uni-font-size-base;
			color: #333;
			padding: 0 20upx;
			box-sizing: border-box;
		}
		.main {
			width: 100%;
			padding: 0 20upx;
			box-sizing: border-box;
			color: #333;
			font-size: $uni-font-size-base;
			line-height: 1.5em;
			.house {
				height: 100upx;
				box-sizing: border-box;
				padding-top: 20upx;
				.scrollView {
					width: 100%;
					height: 100%;

					white-space: nowrap;

					.cateItem {
						display: inline-block;
						margin-right: 42upx;
						height: 60upx;
						padding: 0 30upx;
						line-height: 60upx;
						color: #999999;
						font-size: $uni-font-size-base;
						border: 2upx solid #999999;
						border-radius: 6upx;

						&:last-child {
							margin: 0;
						}

						&.cateActive {
							border: 2upx solid #f36d32;
							color: #fff;
							background-color: #f36d32;
						}
					}
				}
			}
			.room {
				width: 100%;
				padding: 40upx 0;
				display: flex;
				align-content: flex-start;
				justify-content: flex-start;
				flex-wrap: wrap;
				font-size: $uni-font-size-base;
				line-height: 1.5em;
				box-sizing: border-box;
				padding-bottom: 0;
				color: #333333;

				.room_name {
					text-align: center;
					width: 25%;
					height: 60upx;
					line-height: 60upx;
					margin-bottom: 30upx;
					color: #999999;
					border-radius: 6upx;
					&.active {
						color: #fff;
						background-color: #f36d32;
					}
				}
			}
		}
	}
	.roomInfo {
		width: 100%;
		box-sizing: border-box;

		.title {
			height: 100upx;
			color: #999999;
			background-color: #f3f3f3;
			font-size: $uni-font-size-base;
			text-align: center;
			font-weight: 700;
			line-height: 100upx;
		}
		.info {
			width: 100%;
			height: auto;
			padding: 20upx;
			box-sizing: border-box;
			margin-bottom: 10upx;
			background-color: #fff;

			.row {
				width: 100%;
				line-height: 60upx;
				font-size: $uni-font-size-base;
				color: #333;
				display: flex;
				align-items: center;
				justify-content: flex-start;

				.text {
					width: 50%;
					height: 100%;

					&.one {
						width: 100%;
					}

					&.two {
						width: 50%;
					}

					.name {
						display: inline-block;
						margin-right: 20upx;
						min-width: 100upx;
					}
					.content {
						margin-right: 20upx;
					}
				}
			}
		}
	}
}
.footer {
	width: 100%;
	height: 130upx;
	position: fixed;
	left: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: flex-start;
	font-size: $uni-font-size-base;
	background-color: #fff;
	box-sizing: border-box;
	padding-left: 280upx;
	.index,
	.chat {
		width: 140upx;
		height: 100%;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		color: #333333;
		position: absolute;
		top: 0;
		left: 0;
		image {
			width: 40upx;
		}
	}
	.chat {
		left: 140upx;
	}

	.right {
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;

		.block {
			width: 50%;
			height: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			text {
				width: 90%;
				height: 70upx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-size: 100% 100%;
				background-repeat: no-repeat;
				border-radius: 70upx;
				overflow: hidden;
				color: #ffffff;
				&.car {
					background-image: url(../../../static/btn_2.png);
				}
				&.yuding {
					background-image: url(../../../static/btn_1.png);
				}
			}
		}
	}
}
</style>
